package com.zhuiyi.springbootmybatis.config;

import com.zhuiyi.springbootmybatis.filter.UserFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean filterRegistrationBean() {

        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(new UserFilter());        //注册自定义过滤器
        List<String> patterns = new ArrayList<>();
        patterns.add("/*"); // /* 拦截所有请求
        bean.setUrlPatterns(patterns);
        bean.setOrder(0);      //设置执行顺序
        return bean;
    }
}
